#ifndef __BSP_LCD_H
#define __BSP_LCD_H

#include <at32f403a_407.h>

/* 屏幕分辨率 */
#define BSP_LCD_X_PIXELS 240
#define BSP_LCD_Y_PIXELS 135

#define LCD_CS_PRO 							GPIOB          					
#define LCD_CS_PIN 							GPIO_PINS_4
#define LCD_CS_CLOCK 						CRM_GPIOB_PERIPH_CLOCK
#define LCD_CS_On()							LCD_CS_PRO->scr = LCD_CS_PIN 
#define LCD_CS_Off()						LCD_CS_PRO->clr = LCD_CS_PIN   

#define LCD_DC_PRO 							GPIOB
#define LCD_DC_PIN 							GPIO_PINS_14
#define LCD_DC_CLOCK 						CRM_GPIOB_PERIPH_CLOCK
#define LCD_DC_On()							LCD_DC_PRO->scr = LCD_DC_PIN 
#define LCD_DC_Off()						LCD_DC_PRO->clr = LCD_DC_PIN 

#define BUZZER_GPORT						GPIOB
#define BUZZER_GPIO_CLK						CRM_GPIOB_PERIPH_CLOCK
#define BUZZER_PIN							GPIO_PINS_11
#define BUZZER_On()							BUZZER_GPORT->scr = BUZZER_PIN 
#define BUZZER_Off()						BUZZER_GPORT->clr = BUZZER_PIN 

//背光使用模拟PWM控制，使用定时器6输出10KHz的PWM
#define LCD_BL_PRO 							GPIOA
#define LCD_BL_PIN 							GPIO_PINS_8
#define LCD_BL_CLOCK 						CRM_GPIOA_PERIPH_CLOCK
#define LCD_BL_On()							LCD_BL_PRO->scr = LCD_BL_PIN 
#define LCD_BL_Off()						LCD_BL_PRO->clr = LCD_BL_PIN   
//#define LCD_BL_TIM_CLK						CRM_TMR2_PERIPH_CLOCK
//#define LCD_BL_TIM							TMR2
//#define LCD_BL_TIM_AF						TMR2_MUX_11
//#define LCD_BL_CHANNEL						TMR_SELECT_CHANNEL_4

#define LCD_SCL_PRO 						GPIOB
#define LCD_SCL_PIN 						GPIO_PINS_13
#define LCD_SCL_CLOCK 						CRM_GPIOB_PERIPH_CLOCK

#define LCD_SDA_PRO 						GPIOB          					//(MOSI)
#define LCD_SDA_PIN 						GPIO_PINS_15
#define LCD_SDA_CLOCK 						CRM_GPIOB_PERIPH_CLOCK

#define LCD_SPI_PR							SPI2
#define LCD_SPI_CLOCK						CRM_SPI2_PERIPH_CLOCK


void bsp_lcd_init();
void bsp_lcd_display_switch(uint8_t status);
void bsp_lcd_draw_rect(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, const uint8_t *dat);
void bsp_lcd_draw_rect_wait();

#endif
